<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    
	
	<title>_快递交接清单</title>
	<script type="text/javascript">
		var datatable_content;
		var formParam ;
		function onQuery() {
			$("#queryForm").submit();
		}
		function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
			   "bAutoWidth":false,
	           "sAjaxSource":'${ctx}/sendout/query',
	           "fnServerData": callback,
	           "fnRowCallback":rowCallBack,
	           "bFilter": false,
	           "aLengthMenu": [ 10 ],
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true,
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": null},
	                 {"mData": "sendCode"},
	             	 {"mData": "company.companyName"},
	             	 {"mData": "logisticNumber"},
	             	 {"mData": "warehouse.groupName"},
	             	 {"mData": null},
	             	 {"mData": "sendTime"},
	             	 {"mData": null},
	             ] ,
	             "aoColumnDefs":[
					{"aTargets": [5],
    				  "mRender": function (data, display, row) {
    					  return row.sender ? row.sender.realname : "";
     			 		}
  					},
				    {"aTargets": [6],
    			     "mRender": function (data, display, row) {
   	 					return data ? new Date(data.time).Format("yyyy-MM-dd hh:mm:ss") :"";
     					}
  					},
  					{"aTargets": [7],
      				  "mRender": function (data, display, row) {
      					  return row.printTime ? new Date(row.printTime.time).Format("yyyy-MM-dd hh:mm:ss"):"";
       			 		}
    					},
	         	  ], 
			});
		}
		function callback(sSource, aoData, fnCallback ) {
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData.concat(formParam)),
		       "success": fnCallback  
		   });
		}
		/**
		*创建了行的回调
		*nRow为当前的tr
		*/
		function rowCallBack(nRow, aData, iDisplayIndex, iDisplayIndexFull){
			var iDisplayStart = datatable_content.fnSettings()._iDisplayStart;
			$("td:eq(0)", nRow).html(iDisplayStart+iDisplayIndex+1);
		}
		
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
        $(function() {
		    $("#queryForm").validate(); 
		  	$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
			$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
			initTable();
			formParam = $("#queryForm").serializeArray();
       });
         
        function exportExcel(){
      		$("#queryForm").attr("action","${ctx}/sendout/exportExcel");
	        $("#queryForm").submit();
			$("#queryForm").attr("action","${ctx}/sendout/v2_toQuery");
      }
        
       
		//打印快递交接按钮
		function initPrint(item) {
			var sendCode = $("#_sendCode").val();
			if (sendCode == "" ) {
				$(item).attr("href", "#");
				jAlert("装车流水号为空,不能打印!", "错误提示");
				return false;
			}
			$(item).attr("href", "#printExpressInfo");
			packFormDefaultPrinter("expressPrint");
		}

		//打印快递交接单
		function printStyle() {
			showBg();
			$.ajax({
				type : 'post',
				url : '${ctx}/sendout/ajaxPrintExpressList',
				data : 'sendCode=' + $("#_sendCode").val(),
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						initLodop();
						printExpressListStyle(data.content);
					} else if (data.status == "0") {
						jAlert(data.content, "错误提示");
					}
					closeBg();
				},

				error : function() {
					closeBg();
					alert("服务器异常");
				}
			});
		}

		function printExpressListStyle(sendOut) {
			LODOP.PRINT_INIT(sendOut[0].sendCode);
			var headStr = "<table width='100%' cellpadding='0' cellspacing='0' align = 'center' border='1'>";
			headStr += "<thead>"
			headStr += "<tr><td colspan= '8' align = 'center'><h3>快递交接清单</h3></td></tr>";
			headStr += "<tr><td >流水号</td><td colspan= '3'>"
					+ sendOut[0].sendCode
					+ "</td><td>快递公司</td><td colspan= '3'>"
					+ sendOut[0].company.companyName + "</td></tr>";
			headStr += "<tr><td>仓库</td><td colspan= '3'>"
					+ sendOut[0].warehouse.groupName
					+ "</td><td>打印时间</td><td colspan= '3'>"
					+ new Date().Format("yyyy-MM-dd hh:mm:ss") + "</td></tr>";
			headStr += "<tr style='font-size:10pt'><td>快递单号</td><td  colspan= '7'></td></tr>";
			headStr += "</thead>";
			var rows = sendOut.length % 4 == 0 ? Math.floor(sendOut.length / 4)
					: Math.ceil(sendOut.length / 4);
			var m = 0;
			for (var i = 1; i <= rows; i++) {
				headStr += "<tr style='font-size:12pt' >";
				for (var j = 1; j <= 4; j++) {
					if (m < sendOut.length) {
						headStr += "<td  colspan= '2' width='25%' >"
								+ sendOut[m].logisticNumber + "</td>";
						m++;
					} else {
						break;
					}
				}
				headStr += "</tr>";
			}
			headStr += "<tr><td colspan= '6'></td><td colspan= '2' align = 'left'>合计:"+sendOut.length+"</td></tr>";
			headStr += "<tr><td  align = 'left'>仓库签字</td><td   colspan= '3'></td><td  align = 'left'>快递签字</td><td   colspan= '3'></td></tr>";
			headStr += "<tr><td  align = 'left'>时间</td><td   colspan= '3'></td><td  align = 'left'>时间</td><td   colspan= '3'></td></tr>";
			headStr += "</table>";
			LODOP.ADD_PRINT_TABLE(50, 0, "100%", "85%", headStr);
			LODOP.SET_PRINT_PAGESIZE(1, 0, 0, "A4");
			if (LODOP.SET_PRINTER_INDEXA($("#expressPrint").val())) {
				LODOP.PRINT();
			}
		}
	</script>
</head>

<body>
<section class="content">
		<div class="row">
			<div class="col-md-12">
			<div class="box box-solid box-primary">
			<div class="box-header">
					<i class="fa fa-search"></i>
					<h3 class="box-title">搜索栏</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
			<form class="form-search" id="queryForm" action="${ctx}/sendout/v2_toQuery" method="post">
			<div class="form-group row">
			<div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
					<span class="input-group-text">快递公司：</span>
					<select  name="_expressCompany"  id="_expressCompany" class="form-control">
						<option value=""></option>
						<c:forEach items="${cmpList}" var="w">
						   <option value="${w.companyCode}" 
						   <c:if test="${param._expressCompany eq w.companyCode }">selected=selected</c:if>
						   >${w.companyName}</option>
					   </c:forEach>
					</select>
				</div>
			</div>
			
			<div class="col-sm-3">
				<div class="input-textgroup col-sm-12">
					<span class="input-group-text">仓库：</span>
					<select  name="_warehouseCode"  id="_warehouseCode" class="form-control">
						<option value=""></option>
						<c:forEach items="${warehouseList}" var="w">
						   <option value="${w.groupCode}" 
						   <c:if test="${param._warehouseCode eq w.groupCode }">selected=selected</c:if>
						   >${w.groupName}</option>
					   </c:forEach>
					</select>
				</div>
			</div>
			
			 <div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">快递单号:</label>
				<input type="text" id="_expressNo" name="_expressNo"  class="form-control" value="${param._expressNo}"/>
				</div>
				</div>
				
				 <div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">装车流水号:</label>
				<input type="text" id="_sendCode" name="_sendCode"  class="form-control" value="${param._sendCode}"/>
				</div>
				</div>
		</div>	
			
			  <div class="form-group row">
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
				<label class="input-group-text">交接时间:</label> 
			 	<input type="text" name="_fromDate" id="_fromDate"  class="form-control" value="${param._fromDate}" /> 
			 	</div>
			 	</div>
			 	<div class="col-sm-3">
				<div class="input-group col-sm-12">
			 	<label class="input-group-text">至</label> 
			 	<input type="text" name="_toDate" id="_toDate" class="form-control" value="${param._toDate}"/> 
			 	</div>
			 	</div>
				
				<div class="col-sm-3">
				<div class="input-group col-sm-12">
			    	<button type="submit" class="btn btn-info">搜索</button>
			   		<a class="btn btn-primary"  href="#" onclick="exportExcel();return false;">导出快递清单</a>
			   		<a class="btn btn-primary"  role="button" data-toggle="modal"  onclick="initPrint(this);">打印快递交接单</a>
			   	</div>
			    </div>
			    
				</div>
		    </form>
	   
</div>
</div>
</div>
</div>
	
	<div class="form-group row">
		<div class="col-md-12">
			<div class="box box-primary">
				<div class="box-header"></div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
			    <th>序号</th>
			    <th>装车流水号</th>
			    <th>快递公司</th>
			    <th>快递单号</th>
			    <th>仓库</th>
			    <th>操作人</th>
			    <th>交接时间</th>
			    <th>打印时间</th>
			</tr></thead>
		<tbody>
		</tbody>
	</table>
	</div>
	</div>
	</div>
	</div>
	
	<!-- 打印界面 -->
		<div class="modal  fade"tabindex="-1" role="dialog" aria-labelledby="myModalLabel"	aria-hidden="true" id="printExpressInfo">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<h3 id="myModalLabel">
		                                                        打印快递交接信息
						</h3>
						<span id="messageLable"></span>
					</div>
					<div class="modal-body" style="overflow: auto;">
						<div class="form-group row">
							<div class="col-sm-9">
								<div class="input-group col-sm-12">
									<span class="input-group-text"> 选择打印机: </span> 
									<select id="expressPrint" name="expressPrint" class="form-control"  >
			
									</select>
								</div>
							</div>
						</div>
					</div>
					
		               <div class="modal-footer">
						<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="printStyle()"> 立即打印 </a>
						<a class="btn" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
					  </div>
		  	</div>
		  </div>
		</div>
</section>	
</body>
</html>
